{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Intersection of Three Sorted Arrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #binary-search #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #二分查找 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: arraysIntersection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #三个有序数组的交集"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给出三个均为 <strong>严格递增排列 </strong>的整数数组&nbsp;<code>arr1</code>，<code>arr2</code> 和&nbsp;<code>arr3</code>。返回一个由&nbsp;<strong>仅 </strong>在这三个数组中&nbsp;<strong>同时出现&nbsp;</strong>的整数所构成的有序数组。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入: </strong>arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]\n",
    "<strong>输出: </strong>[1,5]\n",
    "<strong>解释: </strong>只有 1 和 5 同时在这三个数组中出现.\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入: </strong>arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764]\n",
    "<strong>输出: </strong>[]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= arr1.length, arr2.length, arr3.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= arr1[i], arr2[i], arr3[i] &lt;= 2000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [intersection-of-three-sorted-arrays](https://leetcode.cn/problems/intersection-of-three-sorted-arrays/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [intersection-of-three-sorted-arrays](https://leetcode.cn/problems/intersection-of-three-sorted-arrays/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3,4,5]\\n[1,2,5,7,9]\\n[1,3,4,5,8]', '[197,418,523,876,1356]\\n[501,880,1593,1710,1870]\\n[521,682,1337,1395,1764]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "\n",
    "        res = []\n",
    "        for i in arr1:\n",
    "            if i in arr2 and i in arr3:\n",
    "                res.append(i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "\n",
    "        res = []\n",
    "        for i in arr1:\n",
    "            if i in arr2 and i in arr3:\n",
    "                res.append(i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        # # 三个数组合并，求字典。因为数组是严格递增，所以每个数值在每个数字里都不重复。\n",
    "        # num=arr1+arr2+arr3\n",
    "        # dic=Counter(num)\n",
    "        # res=[]\n",
    "        # for k,v in dic.items():\n",
    "        #     if v==3:\n",
    "        #         res.append(k)\n",
    "        # return res\n",
    "        a=b=c=0\n",
    "        ans=[]\n",
    "        while a<len(arr1) and b<len(arr2) and c<len(arr3):\n",
    "            if arr1[a]==arr2[b]==arr3[c]:\n",
    "                ans.append(arr1[a])\n",
    "                a+=1\n",
    "                b+=1\n",
    "                c+=1\n",
    "            else:\n",
    "                if arr1[a]<arr2[b]:\n",
    "                    a+=1\n",
    "                elif arr2[b]<arr3[c]:\n",
    "                    b+=1\n",
    "                else:\n",
    "                    c+=1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        i = 0\n",
    "        j = 0\n",
    "        k = 0\n",
    "        res = []\n",
    "        while i < len(arr1) and j < len(arr2) and k < len(arr3):\n",
    "            if arr1[i] == arr2[j] and arr2[j] == arr3[k]:\n",
    "                res.append(arr1[i])\n",
    "                i += 1\n",
    "                j += 1\n",
    "                k += 1\n",
    "            else:\n",
    "                min_val = min(arr1[i], arr2[j], arr3[k])\n",
    "                if arr1[i] == min_val:\n",
    "                    i += 1\n",
    "                elif arr2[j] == min_val:\n",
    "                    j += 1\n",
    "                else:\n",
    "                    k += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "\n",
    "        res1 = []\n",
    "        for i in arr1:\n",
    "            if i in arr2:\n",
    "                res1.append(i)\n",
    "\n",
    "        res2 = []\n",
    "        for j in res1:\n",
    "            if j in arr3:\n",
    "                res2.append(j)\n",
    "        return res2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        p1,p2,p3=0,0,0\n",
    "        ans=[]\n",
    "        while p1<len(arr1) and p2<len(arr2) and p3<len(arr3):\n",
    "            if arr1[p1]==arr2[p2]==arr3[p3]:\n",
    "                ans.append(arr2[p2])\n",
    "                p1+=1\n",
    "                p2+=1\n",
    "                p3+=1\n",
    "            elif arr1[p1]==min(arr1[p1],arr2[p2],arr3[p3]):\n",
    "                p1+=1\n",
    "            elif arr2[p2] == min(arr1[p1], arr2[p2], arr3[p3]):\n",
    "                p2 += 1\n",
    "            elif arr3[p3] == min(arr1[p1], arr2[p2], arr3[p3]):\n",
    "                p3 += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import bisect\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        n2=len(arr2)\n",
    "        tmp=[]\n",
    "        for arr in arr1:\n",
    "            idx=bisect.bisect_left(arr2, arr)\n",
    "            if idx<n2 and arr2[idx]==arr:\n",
    "                tmp.append(arr)\n",
    "            elif idx==n2:\n",
    "                break\n",
    "        n3=len(arr3)\n",
    "        ans=[]     \n",
    "        for data in tmp:\n",
    "            idx=bisect.bisect_left(arr3, data)\n",
    "            if idx<n3 and arr3[idx]==data:\n",
    "                ans.append(data)\n",
    "            elif idx==n3:\n",
    "                break\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        # 暴力解决，三个指针同时遍历三个数组\n",
    "        return list(sorted(list(set(arr1) & set(arr2) & set(arr3))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        p1 = p2 = p3 = 0\n",
    "        while p1 < len(arr1) and p2 < len(arr2) and p3 < len(arr3):\n",
    "            if arr1[p1] == arr2[p2] == arr3[p3]:\n",
    "                ans.append(arr1[p1])\n",
    "                p1 += 1\n",
    "                p2 += 1\n",
    "                p3 += 1\n",
    "            else:\n",
    "                if arr1[p1] < arr2[p2]:\n",
    "                    p1 += 1\n",
    "                elif arr2[p2] < arr3[p3]:\n",
    "                    p2 += 1\n",
    "                else:\n",
    "                    p3 += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(list(set(arr1) & set(arr2) & set(arr3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        p1 = p2 = p3 = 0\n",
    "        while p1 < len(arr1) and p2 < len(arr2) and p3 < len(arr3):\n",
    "            if arr1[p1] == arr2[p2] == arr3[p3]:\n",
    "                ans.append(arr1[p1])\n",
    "                p1 += 1\n",
    "                p2 += 1\n",
    "                p3 += 1\n",
    "            else:\n",
    "                if arr1[p1] < arr2[p2]:\n",
    "                    p1 += 1\n",
    "                elif arr2[p2] < arr3[p3]:\n",
    "                    p2 += 1\n",
    "                else:\n",
    "                    p3 += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for num in arr1:\n",
    "            if num in arr2 and num in arr3:\n",
    "                res.append(num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        def binary_search(nums, target):\n",
    "            left = 0\n",
    "            right = len(nums) - 1\n",
    "            while left <= right:\n",
    "                mid = (left + right) // 2\n",
    "                if nums[mid] < target:\n",
    "                    left = mid + 1\n",
    "                elif nums[mid] > target:\n",
    "                    right = mid - 1\n",
    "                else:\n",
    "                    return mid\n",
    "            return -1\n",
    "        def help(arr1, arr2, arr3):\n",
    "            ans = []\n",
    "            for i in arr1:\n",
    "                if binary_search(arr2, i) >= 0 and binary_search(arr3, i) >= 0:\n",
    "                    ans.append(i)\n",
    "            return ans\n",
    "        n1 = len(arr1)\n",
    "        n2 = len(arr2)\n",
    "        n3 = len(arr3)\n",
    "        if min(n1, n2, n3) == n1:\n",
    "            return help(arr1, arr2, arr3)\n",
    "        elif min(n1, n2, n3) == n2:\n",
    "            return help(arr2, arr1, arr3)\n",
    "        else:\n",
    "            return help(arr3, arr1, arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        \n",
    "        return sorted(list(set(arr1).intersection(set(arr2)).intersection(set(arr3))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "\n",
    "        return sorted(list(set(arr1).intersection(set(arr2).intersection(set(arr3)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(list(set(arr1).intersection(set(arr2)).intersection(set(arr3))))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        # # 三个数组合并，求字典。因为数组是严格递增，所以每个数值在每个数字里都不重复。\n",
    "        # num=arr1+arr2+arr3\n",
    "        # dic=Counter(num)\n",
    "        # res=[]\n",
    "        # for k,v in dic.items():\n",
    "        #     if v==3:\n",
    "        #         res.append(k)\n",
    "        # return res\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1, arr2, arr3):\n",
    "        a = b = c = 0\n",
    "        m=len(arr1)\n",
    "        n=len(arr2)\n",
    "        k=len(arr3)\n",
    "        res=[]\n",
    "        while a<m and b<n and c<k:\n",
    "            if arr1[a]==arr2[b]==arr3[c]:\n",
    "                res.append(arr1[a])\n",
    "                a+=1\n",
    "                b+=1\n",
    "                c+=1\n",
    "            else:\n",
    "                if arr1[a]<arr2[b]:\n",
    "                    a+=1\n",
    "                elif arr2[b]<arr3[c]:\n",
    "                    b+=1\n",
    "                else:\n",
    "                    c+=1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        p1, p2, p3 = 0, 0, 0\n",
    "        m, n, k = len(arr1), len(arr2), len(arr3)\n",
    "        ret = []\n",
    "        while p1 < m and p2 < n and p3 < k:\n",
    "            if arr1[p1] == arr2[p2] == arr3[p3]:\n",
    "                ret.append(arr1[p1])\n",
    "                p1 += 1\n",
    "                p2 += 1\n",
    "                p3 += 1\n",
    "            else:\n",
    "\n",
    "                smallest = float(\"inf\")\n",
    "                j = 0\n",
    "                for i, v in enumerate([arr1[p1], arr2[p2], arr3[p3]]):\n",
    "                    if v < smallest:\n",
    "                        smallest = v\n",
    "                        j = i\n",
    "\n",
    "                if j == 0:\n",
    "                    p1 += 1\n",
    "                elif j == 1:\n",
    "                    p2 += 1\n",
    "                else:\n",
    "                    p3 += 1\n",
    "\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        i, j, k = 0, 0, 0  # 初始化三个指针\n",
    "        result = []  # 结果数组\n",
    "        \n",
    "        # 遍历直到任意数组达到末尾\n",
    "        while i < len(arr1) and j < len(arr2) and k < len(arr3):\n",
    "            if arr1[i] == arr2[j] == arr3[k]:  # 如果三者相等\n",
    "                result.append(arr1[i])\n",
    "                i += 1\n",
    "                j += 1\n",
    "                k += 1\n",
    "            else:\n",
    "                # 找出三者中的最小值，并移动对应的指针\n",
    "                min_val = min(arr1[i], arr2[j], arr3[k])\n",
    "                if arr1[i] == min_val:\n",
    "                    i += 1\n",
    "                if arr2[j] == min_val:\n",
    "                    j += 1\n",
    "                if arr3[k] == min_val:\n",
    "                    k += 1\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        i = 0\n",
    "        j = 0\n",
    "        k = 0\n",
    "        while i < len(arr1) and j < len(arr2) and k < len(arr3):\n",
    "            if arr1[i] == arr2[j] == arr3[k]:\n",
    "                res.append(arr1[i])\n",
    "                i += 1\n",
    "                j += 1\n",
    "                k += 1\n",
    "                continue\n",
    "            if arr1[i] <= arr2[j] and arr1[i] <= arr3[k]:\n",
    "                i += 1\n",
    "            elif arr2[j] <= arr1[i] and arr2[j] <= arr3[k]:\n",
    "                j += 1\n",
    "            else:\n",
    "                k += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        counter = collections.Counter(arr1 + arr2 + arr3)\n",
    "        ans = []\n",
    "        for key in counter.keys():\n",
    "            if counter[key] == 3:\n",
    "                ans.append(key)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        dict = Counter(arr1) + Counter(arr2) + Counter(arr3)\n",
    "        return sorted([k for k, v in dict.items() if v == 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        new_list = []\n",
    "        for i in arr1:\n",
    "            if i in arr2 and i in arr3:\n",
    "                new_list.append(i)\n",
    "        return new_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(set(arr1) & set(arr2) & set(arr3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(set(arr1) & set(arr2) & set(arr3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(list(set(arr3)-(set(arr3)-(set(arr1)-(set(arr1)-set(arr2))))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        return sorted(list(set(arr1) & set(arr2) & set(arr3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        i = 0\n",
    "        j = 0\n",
    "        k = 0\n",
    "        n = len(arr1)\n",
    "        m = len(arr2)\n",
    "        l = len(arr3)\n",
    "        res = []\n",
    "        while i < n and j < m and k < l:\n",
    "            if arr1[i] == arr2[j] and arr1[i] == arr3[k]:\n",
    "                res.append(arr1[i])\n",
    "                i += 1\n",
    "                j += 1\n",
    "                k += 1\n",
    "            else:\n",
    "                min_ = min([arr1[i],arr2[j],arr3[k]])\n",
    "                if min_ == arr1[i]: i += 1\n",
    "                if min_ == arr2[j]: j += 1\n",
    "                if min_ == arr3[k]: k += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:\n",
    "        # 三个数组合并，求字典。因为数组是严格递增，所以每个数值在每个数字里都不重复。\n",
    "        num=arr1+arr2+arr3\n",
    "        dic=Counter(num)\n",
    "        res=[]\n",
    "        for k,v in dic.items():\n",
    "            if v==3:\n",
    "                res.append(k)\n",
    "        return res\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
